package com.ruoyi.web.controller.good;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.good.domain.GoodType;
import com.ruoyi.good.service.IGoodTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 物资类型Controller
 *
 * @author rockvan
 * @date 2023-04-09
 */
@Api("物资类型管理")
@RestController
@RequestMapping("/good/goodtype")
public class GoodTypeController extends BaseController
{
    @Autowired
    private IGoodTypeService goodTypeService;

    /**
     * 查询物资类型列表
     */
    @ApiOperation("获取物资类型列表")
    @PreAuthorize("@ss.hasPermi('good:goodtype:list')")
    @GetMapping("/list")
    public TableDataInfo list(GoodType goodType)
    {
        startPage();
        List<GoodType> list = goodTypeService.selectGoodTypeList(goodType);
        return getDataTable(list);
    }

    /**
     * 导出物资类型列表
     */
    @ApiOperation("导出物资类型列表")
    @PreAuthorize("@ss.hasPermi('good:goodtype:export')")
    @Log(title = "物资类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GoodType goodType)
    {
        List<GoodType> list = goodTypeService.selectGoodTypeList(goodType);
        ExcelUtil<GoodType> util = new ExcelUtil<GoodType>(GoodType.class);
        util.exportExcel(response, list, "物资类型数据");
    }

    /**
     * 获取物资类型详细信息
     */
    @ApiOperation("获取物资类型详细信息")
    @ApiImplicitParam(name = "id", value = "类型编号", required = true, dataType = "int", paramType = "path", dataTypeClass = Integer.class)
    @PreAuthorize("@ss.hasPermi('good:goodtype:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(goodTypeService.selectGoodTypeById(id));
    }

    /**
     * 新增物资类型
     */
    @ApiOperation("新增物资类型")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "类型编号", dataType = "Integer", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "type", value = "物资类型名称", dataType = "Integer", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "orderNum", value = "排序", dataType = "Integer", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "status", value = "状态", dataType = "Integer", dataTypeClass = Integer.class),
    })
    @PreAuthorize("@ss.hasPermi('good:goodtype:add')")
    @Log(title = "物资类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GoodType goodType)
    {
        goodType.setCreateBy(getUsername());
        return toAjax(goodTypeService.insertGoodType(goodType));
    }

    /**
     * 修改物资类型
     */
    @ApiOperation("修改物资类型")
    @PreAuthorize("@ss.hasPermi('good:goodtype:edit')")
    @Log(title = "物资类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GoodType goodType)
    {
        return toAjax(goodTypeService.updateGoodType(goodType));
    }

    /**
     * 删除物资类型
     */
    @ApiOperation("删除物资类型")
    @ApiImplicitParam(name = "ids", value = "类型编号", required = true, dataType = "int", paramType = "path", dataTypeClass = Integer.class)
    @PreAuthorize("@ss.hasPermi('good:goodtype:remove')")
    @Log(title = "物资类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(goodTypeService.deleteGoodTypeByIds(ids));
    }
}
